package com.bjesc_b2c.app.appraiset.mvp.view.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.base.BaseActivity;
import com.bjesc_b2c.app.appraiset.http.IApiActivityRequest;
import com.bjesc_b2c.app.appraiset.utils.CustomSharedPreferences;
import com.rxretrofit_build.util.MapUtil;

import java.util.HashMap;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import rxretrofit_base.model.KeyBean;
import rxretrofit_base.model.ShowType;
import rxretrofit_base.model.TokenBean;
import rxretrofit_base.net.BaseSubscriber;
import rxretrofit_base.net.RxRequest;

/**
 * Created by yidong on 2017/5/27.
 */

public class FollowActivity extends BaseActivity{
    @InjectView(R.id.ed_follow_content)
    EditText contentEdit;
    @InjectView(R.id.tv_title)
    TextView title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_follow);
        ButterKnife.inject(this);
        title.setText("添加跟进");
    }
    @OnClick({R.id.iv_return,R.id.btn_save})
   public void onClick(View view){
        switch(view.getId()){
            case R.id.iv_return:
                finish();
                break;
            case R.id.btn_save:
                addFollow();
                break;
        }

    }
    private void addFollow(){
        String content = contentEdit.getText().toString();
        if (TextUtils.isEmpty(content)){
            showToast("填写跟进内容");
            return;
        }
        String dispatchId = CustomSharedPreferences.getString(this, KeyBean.ORDER_ID.valueOf(), KeyBean.FILE_NAME.valueOf());
        HashMap<String, Object> build = new MapUtil()
                .put("dispatch_id", dispatchId)
                .put("content",content)
                .build();
        RxRequest.request(ShowType.SHOW, RxRequest.getClient(FollowActivity.this, build).create(IApiActivityRequest.class).addFollow(),
                new BaseSubscriber<TokenBean>(FollowActivity.this) {
                    @Override
                    public void onSuccess(TokenBean o) {
                        showToast("添加成功");
                        setResult(11);
                        finish();
                    }

                    @Override
                    public void onFailure(Throwable e) {
                    }
                });
    }

}
